/*    */ package com.zimbra.cs.db;
/*    */ 
/*    */ import com.zimbra.common.stats.RealtimeStatsCallback;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.LogFactory;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import java.io.BufferedReader;
/*    */ import java.io.IOException;
/*    */ import java.io.StringReader;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import java.util.regex.Matcher;
/*    */ import java.util.regex.Pattern;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ class DbStats
/*    */   implements RealtimeStatsCallback
/*    */ {
/* 39 */   private static Log sLog = LogFactory.getLog(DbStats.class);
/* 40 */   private static final Pattern PATTERN_BP_HIT_RATE = Pattern.compile("hit rate (\\d+)");
/*    */   
/*    */   public Map<String, Object> getStatData() {
/* 43 */     Map<String, Object> data = new HashMap();
/*    */     try
/*    */     {
/* 46 */       data.put("db_pool_size", Integer.valueOf(DbPool.getSize()));
/*    */       
/*    */ 
/* 49 */       DbResults results = DbUtil.executeQuery("SHOW ENGINE INNODB STATUS", new Object[0]);
/* 50 */       Integer hitRate = parseBufferPoolHitRate(results.getString("Status"));
/* 51 */       if (hitRate != null) {
/* 52 */         data.put("innodb_bp_hit_rate", hitRate);
/*    */       }
/*    */     } catch (Exception e) {
/* 55 */       sLog.warn("An error occurred while getting current database stats", e);
/*    */     }
/*    */     
/* 58 */     return data;
/*    */   }
/*    */   
/*    */   private static Integer parseBufferPoolHitRate(String innodbStatus) throws IOException
/*    */   {
/* 63 */     ZimbraLog.perf.debug("InnoDB status output:\n%s", new Object[] { innodbStatus });
/* 64 */     BufferedReader r = new BufferedReader(new StringReader(innodbStatus));
/* 65 */     String line = null;
/* 66 */     while ((line = r.readLine()) != null) {
/* 67 */       Matcher m = PATTERN_BP_HIT_RATE.matcher(line);
/* 68 */       if (m.find()) {
/* 69 */         String hitRate = m.group(1);
/* 70 */         ZimbraLog.perf.debug("Parsed hit rate: %s", new Object[] { hitRate });
/* 71 */         return Integer.valueOf(Integer.parseInt(hitRate));
/*    */       }
/*    */     }
/* 74 */     return null;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/db/DbStats.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */